#ifndef NPIPE_H
#define NPIPE_H

class NamedPipe
{
	public:
		NamedPipe();
		virtual ~NamedPipe();

		bool8 create(String& Name, uint32 Timeout, void* Security = (void*)0);

		virtual bool8 initOk();
		void ready();

		HANDLE getEvent();

		bool8 processIO();		// false means fatal pipe error

	protected:
		virtual void connectionReset();
		virtual bool8 getResponse();

	private:
		void connectToClient();
		void postRead();
		void postWrite();
		void closeClient();

	protected:
		enum ProtConsts
		{
			BUFSIZE = 1024
		};
		uint8			ibuf[BUFSIZE];
		uint8			obuf[BUFSIZE+256];
		uint32			iused, oused;

	private:
		enum PrivConsts
		{
			BADINIT, CONNECTING, READING, WRITING,
		};

		LPOVERLAPPED	over;
		HANDLE			hPipe;
		int32			state;
};

#endif
